//
//  MyAccountViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/7/17.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "MyAccountViewController.h"
#import "MyZhangHuTableViewCell.h"
#import "BindingWeChatViewController.h"
#import "BinDingAliPayViewController.h"
#import "BankCardBinDingViewController.h"
#import "ExchangeViewController.h"//兑换
#import "RechargeViewController.h"//提现
#import "PayPasswordViewController.h"//支付密码
#import "IngotRemainingViewController.h"//元宝剩余
#import "GoldRemainingViewController.h"//金币剩余
#import "ImazamoxRemainingViewController.h"//金豆剩余
#import "ZAlertView.h"
#import "ZAlertViewManager.h"
#import "NOPayPasswordViewController.h"
@interface MyAccountViewController ()<UITableViewDelegate,UITableViewDataSource>

{
    UITableView*tabView;//表
    NSArray*titleArr;
    NSArray*infoArr;
    NSDictionary*dataDic;//数据
    NSDictionary*quanxianDic;
}

@end

@implementation MyAccountViewController
-(void)myZhangHuHttpRquest
{
     NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"/user/accountInfo.api?access_token="),NSUD_Obj(@"token")];
  [HTTPURL postRequest:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
      NSLog(@"%@",responseObject);
      dataDic= [PublicTools dictionaryWithJsonString:responseObject[@"data"][@"userDTO"]];
      NSLog(@"%@",dataDic);
      NSString*ingotStr=[NSString stringWithFormat:@"%ld",[dataDic[@"ingot"]integerValue]];
      
       NSString*goldStr=[NSString stringWithFormat:@"%ld",[dataDic[@"gold"]integerValue]];
      NSString*otayoniiStr=[NSString stringWithFormat:@"%ld",[dataDic[@"otayonii"]integerValue]];
      NSString*quotaStr=[NSString stringWithFormat:@"%ld",[dataDic[@"quota"]integerValue]];
      NSString*levelStr=[NSString stringWithFormat:@"%ld",[dataDic[@"level"]integerValue]];infoArr=@[ingotStr,goldStr,otayoniiStr,quotaStr,dataDic[@"growthValue"],levelStr,@"",@"",@"",@"",@"",@""];
      [tabView reloadData];
  } filure:^(NSURLSessionDataTask *task, id error) {
      
  }];
}
-(BOOL)judgeIsEmptyWithString:(NSString *)string
{
    if ([string isEqual:[NSNull null]]||string.length == 0 || [string isEqualToString:@""] || string == nil || string == NULL )
    {
        return YES;
    }
    return NO;
}

-(void)shimingRenZhengHttp
{
 NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"member/getMemberData.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL postRequest:url parameters:@{} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        if (![self judgeIsEmptyWithString:responseObject[@"data"]]) {
            quanxianDic=[PublicTools dictionaryWithJsonString:responseObject[@"data"]];

        }
 } filure:^(NSURLSessionDataTask *task, id error) {
     NSLog(@"%@",error);
 }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self shimingRenZhengHttp];
    [self myZhangHuHttpRquest];
    self.title=@"我的账户";
    titleArr=@[@"元宝剩余",@"金币剩余",@"金豆剩余",@"额度",@"成长值",@"等级",@"兑换",@"充值提现",@"支付密码",@"绑定微信",@"绑定支付宝",@"绑定银行卡"];
    
    infoArr=@[@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@""];
    [self setTab];
    // Do any additional setup after loading the view.
}
-(void)setTab
{
    tabView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, width_screen, height_screen-64) style:1];
    tabView.separatorStyle=0;
    tabView.delegate=self;
    tabView.dataSource=self;
    [tabView registerClass:[MyZhangHuTableViewCell class] forCellReuseIdentifier:@"cell"];

    [self.view addSubview:tabView];
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyZhangHuTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text=titleArr[indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:13];
    cell.infoLab.text=infoArr[indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 12;
}
-(void)isSheZhiPayMiMaHttp
{
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==0)
    {
        NSString*ingotStr=[NSString stringWithFormat:@"%ld",[dataDic[@"ingot"]integerValue]];
        IngotRemainingViewController*vc=[IngotRemainingViewController new];
        vc.yuanbaoNum=ingotStr;
    [self.navigationController pushViewController:vc animated:YES];
 
     }
    if (indexPath.row==1)
    {
         NSString*goldStr=[NSString stringWithFormat:@"%ld",[dataDic[@"gold"]integerValue]];
        GoldRemainingViewController*vc=[GoldRemainingViewController new];
        vc.jinbi=goldStr;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    if (indexPath.row==2)
    {
        NSString*jindouStr=[NSString stringWithFormat:@"%ld",[dataDic[@"otayonii"]integerValue]];
        ImazamoxRemainingViewController*vc=[ImazamoxRemainingViewController new];
        vc.jindou=jindouStr;
        [self.navigationController pushViewController:vc animated:YES];
        
    }


    
    if (indexPath.row==6) {
        [self.navigationController pushViewController:[ExchangeViewController new] animated:YES];
    }
    if (indexPath.row==7) {
        [self.navigationController pushViewController:[RechargeViewController new] animated:YES];
    }
    if (indexPath.row==8) {
        NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"user/resetPasswords.api?access_token="),NSUD_Obj(@"token")];
        [HTTPURL postRequest:url parameters:@{@"userId":@"2"} success:^(NSURLSessionDataTask *task, id responseObject) {
            NSLog(@"%@",responseObject);
            if ([responseObject[@"retFlag"]integerValue]==1) {
                [self.navigationController pushViewController:[PayPasswordViewController new] animated:YES];
            }else{
             [self.navigationController pushViewController:[NOPayPasswordViewController new] animated:YES];
            }
        } filure:^(NSURLSessionDataTask *task, id error) {
            
        }];

        
    }
    if (indexPath.row==9) {
        if ([quanxianDic[@"status"]integerValue]==1) {
            [self.navigationController pushViewController:[BindingWeChatViewController new] animated:YES];
        }else{
        
            [[ZAlertViewManager shareManager] showWithType:AlertViewTypeError];
            
            
            [[ZAlertViewManager shareManager] dismissWithTime:2];

        

        }
        
    }
    if (indexPath.row==10) {
        if ([quanxianDic[@"status"]integerValue]==1) {
        [self.navigationController pushViewController:[BinDingAliPayViewController new] animated:YES];
        }else{
            
            [[ZAlertViewManager shareManager] showWithType:AlertViewTypeError];
            
            
            [[ZAlertViewManager shareManager] dismissWithTime:2];
            
            
            
        }

    }
    if (indexPath.row==11) {
        if ([quanxianDic[@"status"]integerValue]==1) {
        [self.navigationController pushViewController:[BankCardBinDingViewController new] animated:YES];
        }else{
            
            [[ZAlertViewManager shareManager] showWithType:AlertViewTypeError];
            
            
            [[ZAlertViewManager shareManager] dismissWithTime:2];
            
            
            
        }

    }


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
